package com.dream.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author 匠人码农
 * @date 2020/11/06 21:10
 * 概要：
 *     FIlterChain的理解
 *
 */

public class Filter1 implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Filter1 init方法");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("Filter1 前置代码");

        //确认线程
        System.out.println("Filter1 线程：" + Thread.currentThread().getName());

        //确认共有request
        System.out.println("Filter1 request user参数：" + request.getParameter("user"));

        //过滤器链
        chain.doFilter(request,response);

        System.out.println("Filter1 后置代码");
    }

    @Override
    public void destroy() {
        System.out.println("Filer1 destroy方法");
    }
}
